package com.sgx.learning.luban.homework.basictype;

import lombok.Getter;

import java.io.IOException;
import java.io.InputStream;

public class U4 {

    @Getter
    private int value;

    public U4(int v) {
        this.value = v;
    }

    public static U4 read(InputStream is) throws IOException {
        byte[] v = new byte[4];
        try {
            is.read(v);
            int value = 0;
            for (int i = 0;i < 4;i++) {
                value <<= 8;
                value |= v[i] & 0xFF;
            }
            return new U4(value);
        } catch (IOException e) {
            throw e;
        }
    }

    public String getHexValue(){
        return Integer.toHexString(value);
    }
}
